<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <title>Biwatter</title>
  <style>
  </style>
</head>
<body>

<button id="reload">reload</button>

<div id="bs-console"></div>

<script src="../release/biwascheme.js">
;; access twitter
(define (get-timeline type)
  (json->sexp (receive-jsonp (string-append "http://twitter.com/statuses/" type "_timeline.json"))))

;; class user
;(define (protected? user)       (cdr (assoc "protected" user)))
;(define (userid-of user)        (cdr (assoc "id" user)))
;(define (profile-image-of user) (cdr (assoc "profile_image_url" user)))
(define (screen-name-of user)   (cdr (assoc "screen_name" user)))
;(define (location-of user)      (cdr (assoc "location" user)))
;(define (description-of user)   (cdr (assoc "description" uesr)))
;(define (name-of user)          (cdr (assoc "name" user)))
;(define (url-of user)           (cdr (assoc "url" user)))

;; class post 
;(define (truncated? post) (cdr (assoc "truncated" post)))
(define (text-of post)    (cdr (assoc "text" post)))
;(define (postid-of post)  (cdr (assoc "id" post)))
;(define (source-of post)  (cdr (assoc "source" post)))
(define (date-of post)    (parse-date (cdr (assoc "created_at" post))))
(define (user-of post)    (cdr (assoc "user" post)))
(define (screen-name post) 
  (screen-name-of (user-of post)))

(define (describe-post post)
  (print (date->string (date-of post) "~T") 
         ": "
         "<" (screen-name post) "> "
         (text-of post)))

(define (reload-timeline)
  (element-update! ($ "#bs-console") "loading...")
  (let1 timeline (get-timeline "public")
    (console-log timeline)
    (element-empty! ($ "#bs-console"))
    (for-each describe-post timeline)))

(add-handler! ($ "reload") "click" reload-timeline)
(reload-timeline)
</script>

</body>
</html>
<!-- vim: set ft=scheme: -->
